//FirstView Component Constructor
function FirstView() {
	
	//load QuickTiGame2d module
	var quicktigame2d = require('com.googlecode.quicktigame2d');
	
	//create game view
	var self = quicktigame2d.createGameView({
		top: 0,
		left: 0,
		width: "100%",
		height: "100%"
	});
	//set orientation to portrait
	self.orientation = Ti.UI.PORTRAIT;
	//set background color to white
	self.color(1, 1, 1);
	
	//create GameScene
	var GameScene = require('ui/GameScene');
	var game = new GameScene();
	//add game scene to game view
	self.pushScene(game.scene);
	
	game.scene.addEventListener("activated", function(){
		game.load();
		//onclick
		self.addEventListener("touchstart", game.touch);
		//game step
		self.addEventListener('enterframe', game.step);
	});
	
	game.scene.addEventListener("deactivated", function(){
		game.unload();
		//onclick
		self.removeEventListener("touchstart", game.touch);
		//game step
		self.removeEventListener('enterframe', game.step);
	});
	
	// Onload event is called when the game is loaded.
	self.addEventListener('onload', function(e) {
	    // Start the game
	    self.start();
	});
	
	return self;
}

module.exports = FirstView;
